from django.shortcuts import HttpResponse
from .models import Book


def index(request):
    # TODO: 添加数据
    # book = Book(name='三国演义', author='罗贯中', price=200)
    # book = Book(name='西游记', author='吴承恩', price=100)
    # book.save()

    # TODO: 主键-查找数据
    # book = Book.objects.get(pk=2)

    # TODO: 条件查询
    # book = Book.objects.filter(name='三国演义')[0]
    # book = Book.objects.filter(name='三国演义').first()

    # TODO: 查询单个对象
    # book = Book.objects.get(name='三国演义')

    # TODO: 修改数据
    # book = Book.objects.get(name='三国演义')
    # book.price = 150
    # book.save()
    # print(book)

    # TODO: 删除数据
    book = Book.objects.get(name='三国演义')
    book.delete()

    return HttpResponse('数据添加成功')
